﻿#include "HelloWorldScene.h"
#include "CPublicFuns.h"
#include "LoginScene.h"
#include "define.h"
#include "Fighting.h"
#include "PostMsg.h"
#include "SceneManager.h"
#include "MainFrame.h"

USING_NS_CC;

Scene* HelloWorld::createScene()
{
    // 'scene' is an autorelease object
    auto *scene = Scene::create();
    
    // 'layer' is an autorelease object
    auto *layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

	//标题
	CCLabelTTF *pTitle = CCLabelTTF::create(CS_HJSANGUO,G_FONT,G_FONT_SIZE*2);
	pTitle->setPosition(Vec2(origin.x+visibleSize.width/2,origin.y+visibleSize.height-50));
	this->addChild(pTitle,1);

// 	//登录
	CCPublicFuns::CreateLabelBtn(CS_LOGIN,
		this,
		Vec2(origin.x+visibleSize.width/2,origin.y+visibleSize.height/2),
		menu_selector(HelloWorld::menuLoginCallback));

// 	//开始游戏
	CCPublicFuns::CreateLabelBtn(CS_STARTGAME,
		this,
		Vec2(origin.x+visibleSize.width/2,origin.y+visibleSize.height/2+100),
		menu_selector(HelloWorld::menuStratGameCallback));

	// 	//开始游戏2
	CCPublicFuns::CreateLabelBtn(CS_STARTGAME2,
		this,
		Vec2(origin.x+visibleSize.width/2,origin.y+visibleSize.height/2+200),
		menu_selector(HelloWorld::menuStratGameCallback2));

// 
//     /////////////////////////////
//     // 2. add a menu item with "X" image, which is clicked to quit the program
//     //    you may modify it.
// 
//     // add a "close" icon to exit the progress. it's an autorelease object
//     CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
//                                         "CloseNormal.png",
//                                         "CloseSelected.png",
//                                         this,
//                                         menu_selector(HelloWorld::menuCloseCallback));
//     
// 	pCloseItem->setPosition(Vec2(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
//                                 origin.y + pCloseItem->getContentSize().height/2));
// 
//     // create menu, it's an autorelease object
//     CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
//     pMenu->setPosition(CCPointZero);
//     this->addChild(pMenu, 1);
// 
//     /////////////////////////////
//     // 3. add your codes below...
// 
//     // add a label shows "Hello World"
//     // create and initialize a label
//     
//     CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
//     
//     // position the label on the center of the screen
//     pLabel->setPosition(Vec2(origin.x + visibleSize.width/2,
//                             origin.y + visibleSize.height - pLabel->getContentSize().height));
// 
//     // add the label as a child to this layer
//     this->addChild(pLabel, 1);
// 
//     // add "HelloWorld" splash screen"
//     CCSprite* pSprite = CCSprite::create("HelloWorld.png");
// 
//     // position the sprite on the center of the screen
//     pSprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// 
//     // add the sprite as a child to this layer
//     this->addChild(pSprite, 0);
    
    return true;
}


void HelloWorld::menuCloseCallback(Ref* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
	MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
#else
    Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    exit(0);
#endif
#endif
}

void HelloWorld::menuStratGameCallback( Ref* pSender )
{
	Director* pDirector = Director::getInstance();
	Scene *pScene = CFighting::createScene(__String::create(""));
	pDirector->replaceScene(pScene);
	
// 	int iAttAccId=1;
// 	int iRecAccId=1;
// 	CPostMsg post;
// 	post.PostFight(iAttAccId,iRecAccId);
}


void HelloWorld::menuStratGameCallback2( Ref* pSender )
{
// 	Director* pDirector = Director::getInstance();
// 	Scene *pScene = CFightingScene::createScene();
// 	pDirector->replaceScene(pScene);
	CSceneManager::gotoScene(Scene_FightingScene);
}

void HelloWorld::menuLoginCallback( Ref* pSender )
{
// 	Director* pDirector = Director::getInstance();
// 	Scene *pScene = CLoginScene::createScene();
	// 	pDirector->replaceScene(pScene);
	CSceneManager::gotoScene(Scene_LoginScene);
}


void HelloWorld::menuback( Ref* pSender )
{
// 	Director* pDirector = Director::getInstance();
// 	//Scene *pScene = HelloWorld::createScene();
// 	Scene *pScene = CMainFrame::createScene();
// 	pDirector->replaceScene(pScene);

	CSceneManager::gotoScene(Scene_MainFrame);
}

// void HelloWorld::CreateBackBtn( Node *pNote )
// {
// 	Size visibleSize = Director::getInstance()->getVisibleSize();
// 	Vec2 origin = Director::getInstance()->getVisibleOrigin();
// 
// 
// 	CCPublicFuns::CreateLabelBtn(CS_BACK,pNote,Vec2(origin.x+visibleSize.width - 80,40),menu_selector(HelloWorld::menuback));
// }
